<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="news"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/ckeditor/ckeditor.js"></script>
    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }
        .modal-body img {
            width: 100%;
        }
    </style>

        <script type="text/javascript">
            $(function () {
                //初始化一个CKeditor
                var edt = CKEDITOR.replace("ckeditor");

                //弹出设置推荐的模态框
                $(".inputBtn").click(function () {
                    //清空模态框
                    $("#editForm input").val("");
                    //edt.setData("");
                    $("#coverUrl").attr("src", "");
                    var json = $(this).data("json");
                    if (json){
                        //回显数据: 标题/封面/当前数据的id
                        $("#editForm input[name='id']").val(json.id);
                        $("#editForm input[name='coverUrl']").val(json.coverUrl);
                        $("#editForm input[name='title']").val(json.title);
                        $("#editForm input[name='abstracts']").val(json.abstracts);
                        //$("#editForm input[name='releaseTime']").val(json.releaseTime);
                        $("#editForm select[name='typeId']").val(json.typeId);
                        $("#coverUrl").attr("src",json.coverUrl);
                        $.get("/news/getContentById.do", {id: json.id}, function (data) {
                            //文章的内容回显到ckeditor
                            edt.setData(data);
                        }, "html");
                    }
                    //显示模态框
                    $("#inputModal").modal("show");
                });
                //保存按钮点击事件
                $(".submitBtn").click(function () {
                    //把CKEditor中的数据填充到文本域中,再提交表单
                    $("#ckeditor").html(edt.getData());
                    //提交表单
                    $("#editForm").submit();
                })

                //发布功能
                $(".changeIsReleaseBtn").click(function () {
                    var json = $(this).data("json");
                    $.messager.confirm("温馨提示：", "亲，你真的要这样吗？", function () {
                        //发送ajax请求,执行更新状态
                        $.post("/news/changeIsReleaseBtn.do", json, function (data) {
                            //刷新当前页面
                            location.reload();
                        });
                    });
                });
            });

        </script>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">骡窝窝日报管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/news/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success btn-xs inputBtn" >
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>摘要</th>
                    <th>创建时间</th>
                    <th>发布时间</th>
                    <th>是否发布</th>
                    <th>状态</th>
                    <th>文章类型</th>
                    <th>操作</th>
                </tr>
                <#list result.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${entity.coverUrl}" width="100"/></td>
                        <td>${entity.title}</td>
                        <td>${entity.abstracts}</td>
                        <td>${(entity.createTime?string("yyyy-MM-dd"))!}</td>
                        <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                        <td>${entity.isReleaseName}</td>
                        <td>${entity.stateName}</td>
                        <td>${entity.typeName}</td>
                        <td>
                            <a role="button" class="btn btn-primary btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                            <a role="button" class="btn btn-success btn-xs changeIsReleaseBtn" data-json='{"id": ${entity.id}, "isRelease": 1}'>
                                <span class="glyphicon glyphicon-ok"></span> 发布
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#-- news编辑模态框 -->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/news/saveOrUpdate.do" method="post"
                      enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id"/>
                    <input type="hidden" name="coverUrl"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">摘要：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="abstracts"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">文章类型：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="typeId">
                                <#if types??>
                                <#list types as t>
                                    <option value="${t.id}">${t.name}</option>
                                </#list>
                                </#if>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="newsContent.content" id="ckeditor"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>